<!DOCTYPE html>
<html>
<head>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="__PUBLIC__/easyui/locale/easyui-lang-zh_CN.js"></script>
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/gray/easyui.css">
	<link rel="stylesheet" type="text/css" href="__PUBLIC__/easyui/themes/icon.css">
	<script type="text/javascript" src="__PUBLIC__/js/add-tab.js"></script>
</head>
<body>
	<div id="tb" style="padding:5px;height:auto">
		<div style="margin-bottom:5px">
			<span>员工工号:</span>
			<input id="employe_work_id" name="employe_work_id" type="text"/>
			<span>姓名:</span>
			<input id="employe_name" name="employe_name" type="text"/>
			<span>部门:</span>
			<select id="employe_department_id">
				<option value="">--请选择部门--</option>
				{$json}
			</select>
			<a href="#" class="easyui-linkbutton" iconCls="icon-search" onClick="doSearch()">搜索</a>
			<a href="javascript:void(0);" src="__URL__/selectEmploye" class="easyui-linkbutton cs-navi-tab-select" id="select_employe" iconCls="icon-search">查看员工</a>
			<a href="javascript:void(0);" src="__URL__/addEmploye" class="cs-navi-tab easyui-linkbutton" iconCls="icon-employe-add">添加员工</a>
			<a href="javascript:void(0);" src="__URL__/editEmploye" class="easyui-linkbutton cs-navi-tab-edit" id="edit_employe" iconCls="icon-employe-edit">编辑员工</a>
			<a href="javascript:void(0);" class="easyui-linkbutton" id="del_employe" iconCls="icon-employe-del">删除员工</a>
		</div>
	</div>
	<table id="tt" title="员工管理" class="easyui-datagrid" style="width:auto;height:auto;"	idField="employe_id"
			iconCls="icon-employe" pageSize="20" pageList="[20,40,80]" data-options="rownumbers:true,singleSelect:true,url:'__URL__/employeListData',toolbar:'#tb'" pagination="true" fitColumns="true" fit="true">
		<thead>
			<tr>
				<th data-options="field:'employe_name',width:150,align:'center'">姓名</th>
				<th data-options="field:'employe_work_id',width:150,align:'center'">工号</th>
				<th data-options="field:'employe_sex',width:150,align:'center'">性别</th>
				<th data-options="field:'employe_department_id',width:150,align:'center'">部门</th>
				<th data-options="field:'employe_brithday',width:150,align:'center'">生日</th>
				<th data-options="field:'employe_nation',width:150,align:'center'">民族</th>
				<th data-options="field:'employe_native',width:150,align:'center'">籍贯</th>
			</tr>
		</thead>
	</table>
<script type="text/javascript">
	function doSearch(){
		$('#tt').datagrid('load',{
			employe_work_id: $('#employe_work_id').val(),
			employe_name: $('#employe_name').val(),
			employe_department_id:$('#employe_department_id').val()
		});
	}

	
	$(function(){
		var i=1;
		var j=1;
		$('#tt').datagrid({
			onDblClickRow: function(rowIndex,rowData){
					var $this = $('.cs-navi-tab-select');
					var href = $this.attr('src') + '?employe_id=' + rowData.employe_id;
					var title = $this.text()+i;
					i++;
					addTab(title, href);
			}
		});
		$('#select_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				var $this = $('.cs-navi-tab-select');
				var href = $this.attr('src')+'?employe_id='+row.employe_id;
				var title = $this.text()+i;
				i++;
				addTab(title, href);
			}
			else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})

		$('#edit_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			if(row){
				var $this = $('.cs-navi-tab-edit');
				var href = $this.attr('src')+'?employe_id='+row.employe_id;
				var title = $this.text()+j;
				j++;
				addTab(title, href);
			}
			else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})
		$('#del_employe').click(function(){
			var row = $('#tt').datagrid('getSelected');
			
            if(row) {
                $.messager.confirm('提示信息', '是否删除该员工信息?', function(r){
                    if(r){
                        $.ajax({
                        	type:'post',
                            url: '__URL__/delEmploye',
                            data: {employe_id: row.employe_id },
                            success: function (data) {
                            	if(data=='ok'){
                            		$.messager.alert('提示', '删除成功', 'info');
                            		$('#tt').datagrid('reload');
                            	} 
                                if(data=='no'){
                                	$.messager.alert('提示', '删除失败', 'info');
                                }
                            }
                        });
                    }
                });
            }
            else {
            	$.messager.alert('提示', '请选择员工', 'info');
            }
		})
	});	
</script>
</body>
</html>